package com.ruoyi.hcmain.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.hcmain.domain.HcOutinfo;
import com.ruoyi.hcmain.domain.HcReceive;
import com.ruoyi.hcmain.domain.HcStock;
import com.ruoyi.hcmain.service.IHcOutinfoService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.hcmain.domain.HcDispatch;
import com.ruoyi.hcmain.service.IHcDispatchService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 出库列Controller
 * 
 * @author ruoyi
 * @date 2023-08-15
 */
@RestController
@RequestMapping("/hcmain/dispatch")
public class HcDispatchController extends BaseController
{
    @Autowired
    private IHcDispatchService hcDispatchService;
    @Autowired
    private IHcOutinfoService hcOutinfoService;

    /**
     * 查询出库列列表
     */
    @PreAuthorize("@ss.hasPermi('hcmain:dispatch:list')")
    @GetMapping("/list")
    public TableDataInfo list(HcDispatch hcDispatch)
    {
        startPage();
        List<HcDispatch> list = hcDispatchService.selectHcDispatchList(hcDispatch);
        return getDataTable(list);
    }

    @GetMapping("/getoutlist")
    public AjaxResult getoutlist(HcOutinfo hcReceive)
    {
        List<HcOutinfo> hcStocks= hcOutinfoService.selectHcOutinfoList(null);
        List<Map<String,String>> maps=new ArrayList<>();
        for (HcOutinfo hcOutinfo:hcStocks){
            Map<String,String> map=new HashMap<>();
            map.put("value",hcOutinfo.getOutinfoId().toString());
            map.put("label",hcOutinfo.getNames());
            maps.add(map);
        }
        return success(maps);
    }

    /**
     * 导出出库列列表
     */
    @PreAuthorize("@ss.hasPermi('hcmain:dispatch:export')")
    @Log(title = "出库列", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HcDispatch hcDispatch)
    {
        List<HcDispatch> list = hcDispatchService.selectHcDispatchList(hcDispatch);
        ExcelUtil<HcDispatch> util = new ExcelUtil<HcDispatch>(HcDispatch.class);
        util.exportExcel(response, list, "出库列数据");
    }

    /**
     * 获取出库列详细信息
     */
    @PreAuthorize("@ss.hasPermi('hcmain:dispatch:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(hcDispatchService.selectHcDispatchById(id));
    }

    /**
     * 新增出库列
     */
    @PreAuthorize("@ss.hasPermi('hcmain:dispatch:add')")
    @Log(title = "出库列", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HcDispatch hcDispatch)
    {
        return toAjax(hcDispatchService.insertHcDispatch(hcDispatch));
    }

    /**
     * 修改出库列
     */
    @PreAuthorize("@ss.hasPermi('hcmain:dispatch:edit')")
    @Log(title = "出库列", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HcDispatch hcDispatch)
    {
        return toAjax(hcDispatchService.updateHcDispatch(hcDispatch));
    }

    /**
     * 删除出库列
     */
    @PreAuthorize("@ss.hasPermi('hcmain:dispatch:remove')")
    @Log(title = "出库列", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(hcDispatchService.deleteHcDispatchByIds(ids));
    }
}
